package cn.donave.framework.tree.impl;

import java.util.ArrayList;
import java.util.List;

import cn.donave.component.cms.pojo.DnCmsColumn;
import cn.donave.component.cms.service.ICmsFoldService;
import cn.donave.component.cms.service.impl.CmsFoldServiceImpl;
import cn.donave.framework.tree.Tree;
import cn.donave.framework.tree.TreeNode;

/**
 * 
 * @author majun
 * 
 * @date 2011-5-20
 * @version 1.0
 */
public class ContentFolderTreeImpl implements Tree {

	private ICmsFoldService cmsFoldService = CmsFoldServiceImpl.getInstance();

	@SuppressWarnings( { "unchecked" })
	public List generateTree(String id, String action, String webRoot)
			throws Exception {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		TreeNode node = null;
		List<DnCmsColumn> columnList = cmsFoldService
				.findSubFoldersByParentId(id);
		for (DnCmsColumn column : columnList) {
			node = new TreeNode();
			node.setIcon("org.png");
			node.setOpenIcon("org.png");
			node.setAction(action + "?columnId=" + column.getId());
			node
					.setSrc(webRoot
							+ "/treeServlet?kind=cn.donave.framework.tree.impl.ContentFolderTreeImpl&amp;id="
							+ column.getId() + "&amp;action=" + action);

			node.setId(column.getId());
			node.setText(column.getName());
			node.setTarget("frmRight");
			long count = this.cmsFoldService.findCountOfSubFolders(column
					.getId());
			if (count != 0)
				node.setHaveChild("true");
			nodeList.add(node);
		}
		return nodeList;
	}

}
